﻿using System;
using Microsoft.EntityFrameworkCore;
using courseProjectV1.Controllers;
namespace courseProjectV1.Db
{
    public class DataBaseContext : DbContext
    {
        public DbSet<Role> Roles { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<UserInfo> UserInfos { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<Bid> Bids { get; set; }
        public DbSet<ComplitedProduct> ComplitedProducts { get; set; }

        public DataBaseContext(DbContextOptions<DataBaseContext> options) : base(options)
        {
            Database.EnsureCreated();
        }
        protected override void OnModelCreating(ModelBuilder model)
        {
            Role admin = new Role()
            {
                Id = 1,
                Name = "Administrator"
            };
            model.Entity<Role>().HasData(admin,
            new Role()
            {
                Id = 2,
                Name = "Client"
            },
            new Role()
            {
                Id = 3,
                Name = "Seller"
            });
            //model.Entity<User>().HasData(new User()
            //{
            //    Id = 1,
            //    Login = "admin",
            //    Password = AccountController.encode("1234"),
            //    Role = admin
            //});
            //model.Entity<User>().HasOne(p=> p.Role).WithOne();
        }
    }
}

